package indi.zhifa.recipe.bailan.busy.service.impl;

import indi.zhifa.recipe.bailan.busy.enums.EOrmEntityStatus;
import indi.zhifa.recipe.bailan.busy.service.IOrmMybatisService;
import indi.zhifa.recipe.bailan.busy.dao.mapper.OrmTestMybatisMapper;
import indi.zhifa.recipe.bailan.busy.entity.po.OrmTestEntity;
import indi.zhifa.recipe.bailan.busy.entity.vo.PageData;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
@Service
public class OrmMybatisServiceImpl extends BaseOrmServiceImpl implements IOrmMybatisService {

    private final OrmTestMybatisMapper mOrmTestMybatisMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void initTestData() {
        List<OrmTestEntity> iniOrmTestEntityList = getInitOrmTestEntityList("mybatis");
        mOrmTestMybatisMapper.saveBatch(iniOrmTestEntityList);
    }

    @Override
    public PageData<OrmTestEntity> page(int pCurrent, int pSize,
                                        String pAppCode, String pModuleCode, String pCode, String pName,
                                        EOrmEntityStatus pStatus, Integer pMin, Integer pMax) {
        List<OrmTestEntity> OrmTestEntityList = mOrmTestMybatisMapper.page(pCurrent,pSize,
                pAppCode,pModuleCode,pCode,pName,
                null !=pStatus ? pStatus.getCode():null,pMin,pMax);
        PageData<OrmTestEntity> data = new PageData<>();
        data.setCurrent(pCurrent);
        data.setSize(pSize);
        data.setPageData(OrmTestEntityList);
        return data;
    }

}
